function oldpath = rmpath_bcoe(searchstring,report)
% function oldpath = rmpath_bcoe(searchstring,[report])
% to remove folders from the path
% bcoe
if nargin<2
    report=0;
end

if nargout>0
    oldpath = path;
end

ps = pathsep;
% Make cell array of MATLABPATH directories
cmdirs = regexp([matlabpath ps],['.[^' ps ']*' ps],'match')';

char_loc=strfind(cmdirs,searchstring);
cell_loc=find(cellfun(@(x) ~isempty(x), char_loc));
if ~isempty(cell_loc)
    if(report)
        disp('the following items have been removed');
        cmdirs(cell_loc)
    end;
    cmdirs(cell_loc)=[];
    matlabpath([cmdirs{:}])
else
    fprintf('---> unable to find %s in current path\n',searchstring)
end

